package com.mashiguang.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.memory.InMemoryDaoImpl;
import org.springframework.stereotype.Service;

public class InMemoryChangePasswordDaoImpl extends InMemoryDaoImpl implements
		IChangePassword {
	
	private static Logger log = LoggerFactory.getLogger(InMemoryChangePasswordDaoImpl.class);

	public void changePassword(String username, String password) {
		User u = (User) getUserMap().getUser(username);
		
		log.debug("old password is {}",u.getPassword());
		
		User newuser = new User(username, 
				password, 
				u.isEnabled(), 
				u.isAccountNonExpired(), 
				u.isCredentialsNonExpired(), 
				u.isAccountNonLocked(), 
				u.getAuthorities());
		
		getUserMap().addUser(newuser);
		
	}

}
